#define _CRT_SECURE_NO_WARNINGS 1

#include"AVLTree.h"

void test1()
{
	AVLTree<int, int> Tree;
	int a[] = { 10,20,15,30,40,50,18,50,60 };
	for (auto e : a)
	{
		Tree.Insert(make_pair(e,e));
	}
	Tree.Inorder();
	cout << Tree.Height() << endl;
	cout << Tree.IsBalance() << endl;
	cout << Tree.Find(10) << endl;
	cout << Tree.Find(1000) << endl;
}

void test2()
{
	int cnt = 10000000;
	AVLTree<int,int> Tree;
	while (cnt)
	{
		int num = rand() % 10000000;
		Tree.Insert(make_pair(num,num));
		--cnt;
	}
	cout << Tree.Height() << endl;
	cout << Tree.IsBalance() << endl;
}

void test3()
{
	AVLTree<int, int> Tree;
	int a[] = { 10,20,15,30,40,50,18,50,60 };
	for (auto e : a)
	{
		Tree.Insert(make_pair(e, e));
	}
	Tree.Inorder();

	//cout << Tree.IsBalance() << endl;
	Tree.Erase(10);
	//cout << Tree.IsBalance() << endl;
	//Tree.Inorder();

	//cout << Tree.IsBalance() << endl;
	Tree.Erase(20);
	//cout << Tree.IsBalance() << endl;
	//Tree.Inorder();

	//cout << Tree.IsBalance() << endl;
	Tree.Erase(15);
	//cout << Tree.IsBalance() << endl;
	//Tree.Inorder();

	Tree.Erase(30);
	//cout << Tree.IsBalance() << endl; 
	//Tree.Inorder();

	Tree.Erase(40);
	//cout << Tree.IsBalance() << endl; 
	//Tree.Inorder();

	Tree.Erase(50);
	//Tree.Inorder();
	//cout << Tree.IsBalance() << endl; 

	Tree.Erase(18);
	Tree.Inorder();
	cout << Tree.IsBalance() << endl;

	Tree.Erase(60);
	//cout << Tree.IsBalance() << endl;
	//Tree.Inorder();
}

void test4()
{
	AVLTree<int, int> Tree;
	int a[] = { 10,20,15,30,40,50,18,50,60 };
	for (auto e : a)
	{
		Tree.Insert(make_pair(e, e));
	}
	Tree.Inorder();

	Tree.Erase(10);
	Tree.Erase(40);
	Tree.Erase(60);
	Tree.Erase(50);
	cout << Tree.IsBalance() << endl;
	Tree.Inorder();
}

int main()
{
	//test1();
	//test2();
	//test3();
	test4();
	return 0;
}

